{% extends "admin/layout.html" %}

{% block title %}{{ title }} - 后台管理系统{% endblock %}

{% block page_title %}{{ title }}{% endblock %}

{% block breadcrumb %}
<li class="breadcrumb-item"><a href="{{ url_for('admin.admin_member.member_management') }}">员工管理</a></li>
<li class="breadcrumb-item active">{{ title }}</li>
{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-10">
        <div class="card">
            <div class="card-body">
                <form method="post" id="memberForm" novalidate>
                    {{ form.hidden_tag() }}
                    <div id="formErrors" class="alert alert-danger d-none"></div>

                    <div class="mb-3">
                        {{ form.name.label(class="form-label") }}
                        {{ form.name(class="form-control", required=form.name.flags.required, **{'aria-describedby': 'name-error' if form.name.errors else ''}) }}
                        {% if form.name.errors %}
                        <div id="name-error" class="invalid-feedback d-block">
                            {{ form.name.errors[0] }}
                        </div>
                        {% endif %}
                    </div>

                    <div class="mb-3">
                        {{ form.mobile.label(class="form-label") }}
                        {{ form.mobile(class="form-control", **{'aria-describedby': 'mobile-error' if form.mobile.errors else ''}) }}
                        {% if form.mobile.errors %}
                        <div id="mobile-error" class="invalid-feedback d-block">
                            {{ form.mobile.errors[0] }}
                        </div>
                        {% endif %}
                    </div>

                    <div class="mb-3">
                        {{ form.email.label(class="form-label") }}
                        {{ form.email(class="form-control", **{'aria-describedby': 'email-error' if form.email.errors else ''}) }}
                        {% if form.email.errors %}
                        <div id="email-error" class="invalid-feedback d-block">
                            {{ form.email.errors[0] }}
                        </div>
                        {% endif %}
                    </div>

                    <div class="mb-3">
                        {{ form.department.label(class="form-label") }}
                        {{ form.department(class="form-select", **{'aria-describedby': 'department-error' if form.department.errors else ''}) }}
                        {% if form.department.errors %}
                        <div id="department-error" class="invalid-feedback d-block">
                            {{ form.department.errors[0] }}
                        </div>
                        {% endif %}
                    </div>

                    <div class="mb-3">
                        {{ form.position.label(class="form-label") }}
                        {{ form.position(class="form-control", **{'aria-describedby': 'position-error' if form.position.errors else ''}) }}
                        {% if form.position.errors %}
                        <div id="position-error" class="invalid-feedback d-block">
                            {{ form.position.errors[0] }}
                        </div>
                        {% endif %}
                    </div>

                    <div class="mb-3">
                        {{ form.wecom_userid.label(class="form-label") }}
                        {{ form.wecom_userid(class="form-control", **{'aria-describedby': 'wecom_userid-error' if form.wecom_userid.errors else ''}) }}
                        {% if form.wecom_userid.errors %}
                        <div id="wecom_userid-error" class="invalid-feedback d-block">
                            {{ form.wecom_userid.errors[0] }}
                        </div>
                        {% endif %}
                    </div>



                    <div class="mb-3">
                        <div class="form-check form-switch">
                            {{ form.status(class="form-check-input") }}
                            {{ form.status.label(class="form-check-label") }}
                        </div>
                    </div>

                    <div class="d-grid gap-2">
                        <button type="submit" class="btn btn-primary" aria-label="保存员工信息" onclick="event.preventDefault(); document.getElementById('memberForm').submit();">保存</button>
                        <a href="{{ url_for('admin.admin_member.member_management') }}" class="btn btn-secondary">取消</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}